#pragma once
#include <vector>
#include "todaycmn.h"

using namespace std;


class TodayHost
{
public:
	TodayHost(HWND hostWindowHwnd)
	{
		_hostWindow = hostWindowHwnd;
		_heightUsed  = 0;
		_backgroundBitmap = 0;
		_selectedItem = -1;
		_scrollPos = 0;

		GetWindowRect(hostWindowHwnd, &_windowSize);
		SetTimer(_hostWindow, TODAY_REFRESH_TIMER, 1000, (TIMERPROC) NULL);
		SetScrollRange(_hostWindow, SB_VERT, 0, 0, false);
		InitializeCriticalSection(&_backgroundSync);
	}
	~TodayHost()
	{
		KillTimer(_hostWindow, TODAY_REFRESH_TIMER);
		DeleteCriticalSection(&_backgroundSync);
	}

	void SetBackground(TCHAR* path);
	void LoadPlugin(TODAYLISTITEM item);
	void UnloadAllPlugins();
	bool HasSelectedPlugin();
	LRESULT MessageHandler(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);

private:
	void UpdateTodayPlugins(bool reorder = false);
	void NotifyLostSelection(HWND exceptWnd);
	int TodayHost::ProcessNavigationMessages(WPARAM wParam);
	void InitToday();
	void DrawTodayBackground(HWND hWnd);
	void UpdateScrollPos();
//	int GetPxByScrollPos(int scrollPos);
//	int GetScrollPosByPx(int px);


private:
	static const int TODAY_REFRESH_TIMER = 1;
	static const int LineHeight = 5;

	int _selectedItem;
	RECT _windowSize;
	HWND _hostWindow;
	int _heightUsed;
	int _scrollPos;
	vector<TODAYLISTITEM> _loadedPlugins;
	HBITMAP _backgroundBitmap;
	CRITICAL_SECTION _backgroundSync;
};
